package com.ibeetl.admin.api.service;

import com.ibeetl.admin.api.dao.TravelAudioDao;
import com.ibeetl.admin.api.entity.Travel_audio_list;
import com.ibeetl.admin.api.util.BeanToMap;
import com.ibeetl.admin.core.service.CoreBaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class TravelAudioService extends CoreBaseService<Travel_audio_list> {
    @Resource
    private TravelAudioDao travelAudioDao;

    public List<Travel_audio_list> queryByAttractionId(Long attractionId,Long userId) {

        return travelAudioDao.queryByAttractionId( attractionId,userId);

    }

    public Long queryNewIdByAttractionId(Long attractionId,Long userId) {
        List<Long> list = travelAudioDao.queryNewIdByAttractionId( attractionId,userId);
        if(list == null || list.size()<1) return null;
        return list.get(0);
    }

    public List<Travel_audio_list> queryByAttsId(Long attsId,Long userId) {

        return travelAudioDao.queryByAttsId( attsId,userId);

    }

    public void delete( Long audioId,int state) {
        travelAudioDao.updateState(audioId,state);
    }

    public boolean saveData(Travel_audio_list travelAudio) {
        travelAudio.setCreateDt(new Date());
        try{
            Map map = BeanToMap.beanToMap(travelAudio);
            travelAudioDao.save(map);
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
